package com.shunan.miaosha.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import com.shunan.miaosha.beans.Users;

@Mapper
public interface UserDao {
	@Select("select * from users where id=#{id}")
	Users findUserByID(@Param("id")int id);
	
	@Select("SELECT * FROM users WHERE users.name=#{name} AND users.password=#{password}")
	Users findUser(@Param("name")String name,@Param("password")String password);
	
	@Select("SELECT * FROM users WHERE users.name=#{name}")
	List<Users> findUsers(@Param("name")String name);
	
/*	@Insert("insert users(id,name) values(#{id},#{name});select last_insert_id();")
	int insertUser(@Param("id")int id,@Param("name")String name);
*/	
	@Insert("insert users(name,password,salt) values(#{name},#{password},#{salt});")
	@SelectKey(keyColumn="id", keyProperty="id", resultType=int.class, before=false, statement="select last_insert_id()")
	int insertUser(@Param("name")String name,@Param("password")String password,@Param("salt")String salt);
}
